package com.meirengu.webview.service.impl;

import com.meirengu.webview.model.KwUserError;
import com.meirengu.webview.model.UserInfo;
import com.meirengu.webview.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SearchCreditCardimpl implements SearchCreditCardService {

    @Autowired
    UserService userService;
    @Autowired
    UserInfoService userInfoService;
    @Autowired
    KwAydFilterService kwAydFilterService;
    @Autowired
    KwCyphFilterService kwCyphFilterService;
    @Autowired
    KwDfrzFilterService kwDfrzFilterService;
    @Autowired
    KwXxjrFilterService kwXxjrFilterService;
    @Autowired
    KwYcdFilterService kwYcdFilterService;
    @Autowired
    KwZhudaiFilterService kwZhudaiFilterService;
    @Autowired
    KwUserErrorService kwUserErrorService;
    @Autowired
    KwWeidaiFilterService kwWeidaiFilterService;


    public Integer findCreditCard() throws Exception {
        Map<String, Object> map = new HashMap<>();
        map.put("createTimeBegin", "2018-06-25");
        map.put("createTimeEnd", "2018-06-26");
        List<Map<String, Object>> users = userService.getList(map);
        Integer count = 0;
        Integer num = 0;
        A:
        for (Map<String, Object> map1 : users) {
            boolean flag = true;
            String mobile = (String) map1.get("mobile");
            String id = (String) map1.get("id");
            Map<String, Object> mobileMap = new HashMap<>();
            UserInfo userInfo = userInfoService.getByUserId(id);
            if (userInfo != null && userInfo.getCredit() != null) {
                if (userInfo.getCredit() == 2) {
                    num++;
                    System.out.println(num);
                    Map<String, Object> filterMap = new HashMap<>();
                    filterMap.put("mobile", mobile);
                    filterMap.put("suited", "N");
                    List<Map<String, Object>> aydUser = kwAydFilterService.getList(filterMap);
                    if (aydUser.size() < 3) {
                        flag = false;
                        continue A;
                    }
                    List<Map<String, Object>> CyphUser = kwCyphFilterService.getList(filterMap);
                    if (CyphUser.size() < 1) {
                        flag = false;
                        continue A;
                    }
                    List<Map<String, Object>> DfrzUser = kwDfrzFilterService.getList(filterMap);
                    if (DfrzUser.size() < 1) {
                        flag = false;
                        continue A;
                    }
                    List<Map<String, Object>> XxjrUser = kwXxjrFilterService.getList(filterMap);
                    if (XxjrUser.size() < 1) {
                        flag = false;
                        continue A;
                    }
                    List<Map<String, Object>> ycdUser = kwYcdFilterService.getList(filterMap);
                    if (ycdUser.size() < 2) {
                        flag = false;
                        continue A;
                    }
                    List<Map<String, Object>> zhudaiUser = kwZhudaiFilterService.getList(filterMap);
                    if (zhudaiUser.size() < 1) {
                        flag = false;
                        continue A;
                    }
                    List<Map<String, Object>> weidaiUser = kwWeidaiFilterService.getList(filterMap);
                    if (weidaiUser.size() < 1) {
                        flag = false;
                        continue A;
                    }

                }
                if (flag) {
                    KwUserError kwUserError = new KwUserError();
                    kwUserError.setMobile(mobile);
                    kwUserErrorService.insert(kwUserError);
                    count++;
                    System.out.println(count);
                }
            }
        }
        return count;
    }


}
